/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelBiseccion.java
 *
 * Created on 11-oct-2010, 14:12:47
 */
package interfaz.FuncionPanels;

//import java.awt.FlowLayout;
//import javax.print.DocFlavor.STRING;
//import javax.management.monitor.GaugeMonitor;
import interfaz.NuMethodApp;
import javax.swing.JFrame;
//import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

//import javax.swing.table.TableModel;
import metodos.sistec.GaussSeidel;
import metodos.sistec.Jacobi;
//import org.jdesktop.swingx.JXTable;

/**
 *
 * @author The NuMethod Team
 */
public class PanelIterativosAbiertos extends javax.swing.JPanel {

    /** Creates new form PanelBiseccion */
    public PanelIterativosAbiertos() {
        initComponents();
        initComponents2();
    }

    private void initComponents2() {
        //this.jTable1.setVisible(false);
        this.TableA.setEditable(true);
        TableA.setShowGrid(true);
        TableA.setOpaque(true);
        TableA.setAutoStartEditOnKeyStroke(true);
        TableA.setRolloverEnabled(true);
        TableA.setSurrendersFocusOnKeystroke(true);
        TableA.setTerminateEditOnFocusLost(true);
        TableA.setFillsViewportHeight(true);

        TableA.setEditable(false);
        TableB.setEditable(false);
        TableX.setEditable(false);
//        TableA.setAutoResizeMode(JXTable.AUTO_RESIZE_LAST_COLUMN);
//        TableB.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF);
//        TableX.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF);
        TableA.setVisibleColumnCount(0);

        rebuildTableModels(3);

        
    }

    /**
     * Este metodo devuelve los valores existentes en las tablas a dos variables
     * <br>Pasadas como parametro.
     * 
     * <p>
     * WARNING: esta version hasta ahora no soporta variables distintas a numeros<br>
     * asi que se debe de tener cuidado de no ingresar ningun valor que no sea numerico en las tablas.
     * @param A
     * @param B
     */
    private void getDataFromTables(double[][] A, double[] B) {
        int rowCount = this.TableA.getModel().getRowCount();
        int columnCount = this.TableA.getModel().getColumnCount();
        // A = new double[rowCount][columnCount];
        //Obtener los datos desde el modelo de tabla actual
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < columnCount; j++) {
                A[i][j] = Double.parseDouble(TableA.getModel().getValueAt(i, j).toString());
                System.out.print(Double.parseDouble(this.TableA.getModel().getValueAt(i, j).toString()) + " ");
            }
            System.out.println("");
        }

        //Obtener los datos desde la tabla B
        //B = new double[rowCount];
        for (int i = 0; i < B.length; i++) {
            B[i] = Double.parseDouble(TableB.getModel().getValueAt(i, 0).toString());
        }
    }

    /**
     * Este metodo coloca datos tipo Double en la tabla X.
     * <br>WARNING: este metodo depende estrictamente de sus valores, cualquier intento de
     * <br>utilizar este metodo con unos datos extraños terminara en error
     * @param X los datos a poner en la tablaX
     */
    private void setDataToTableX(double[] X) {
        Double[] aX = new Double[X.length];
        int n = X.length;
        //La tabla solo recibe objetos tipo Double con "D" mayuscula, el tipo basico double con "d" minuscula no es un Object.
        for (int i = 0; i < n; i++) {
            aX[i] = new Double(X[i]);
        }

        DefaultTableModel t = (DefaultTableModel) TableX.getModel();

        for (int i = 0; i < n; i++) {
            t.setValueAt(aX[i], 0, i);
        }

        //Actualizar los datos en la tabla
        t.fireTableDataChanged();

    }


    public void updateTableModels (){
        //COnfigurar los modelos de tabla para las 3 tablas disponibles.
            DefaultTableModel m = PanelMatriz.getMa();
            this.TableA.setModel(m);

            DefaultTableModel mB = PanelMatriz.getMb();
            this.TableB.setModel(mB);

            DefaultTableModel mX = PanelMatriz.getMx();
            TableX.setModel(mX);

            //Construir el Modelo para la tabla relajacion
            int a = m.getColumnCount();
            Double[][] test = new Double[1][a];
            String[] names = new String[a];


            for (int i = 0; i < a; i++) {
                String aTest = "Inicial " + (i + 1);
                names[i] = aTest;
            }

            DefaultTableModel tm = new DefaultTableModel(test, names);

            TableRelajacion.setModel(tm);
            tm.fireTableDataChanged();

            m.fireTableDataChanged();
            mB.fireTableDataChanged();
            mX.fireTableDataChanged();
    }
      
    /**
     * Metodo que reconstruye de forma dinamica los modelos de tabla
     * luego de cada entrada de datos
     * @param a
     */
    private void rebuildTableModels (Integer a){
         //Constuir el modelo para la tabla A
            Double[][] test = new Double[a][a];
            String[] names = new String[a];

            for (int i = 0; i < a; i++) {
                String aTest = "X" + (i + 1);
                names[i] = aTest;
            }

            //Constuir el modelo para la tabla B
            Double[][] testB = new Double[a][1];
            String[] namesB = new String[1];

            for (int i = 0; i < 1; i++) {
                String aTest = "B" + (i + 1);
                namesB[i] = aTest;
            }

            //Construir el Modelo para la tabla X
            Double[][] testX = new Double[1][a];
            String[] namesX = new String[a];


            for (int i = 0; i < a; i++) {
                String aTest = "X" + (i + 1);
                namesX[i] = aTest;
            }

            //COnfigurar los modelos de tabla para las 3 tablas disponibles.
            DefaultTableModel m = new DefaultTableModel(test, names);
            this.TableA.setModel(m);

            DefaultTableModel mB = new DefaultTableModel(testB, namesB);
            this.TableB.setModel(mB);

            DefaultTableModel mX = new DefaultTableModel(testX, namesX);
            TableX.setModel(mX);

            //        for (int i =0; i < a; i++ ){
            //            for (int j= 0; j < a; j++){
            //                jTable1.setValueAt(25, i, j);
            //            }
            //        }
            m.fireTableDataChanged();
            mB.fireTableDataChanged();
            mX.fireTableDataChanged();
            //TableA.repaint();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TableA = new org.jdesktop.swingx.JXTable();
        jButton2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        TableB = new org.jdesktop.swingx.JXTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        TableX = new org.jdesktop.swingx.JXTable();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        FieldIteraciones = new javax.swing.JTextField();
        FieldRelajacion = new javax.swing.JTextField();
        FieldTolerancia = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        BotonJacobi = new javax.swing.JButton();
        BotonGaussSeidelRelax = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        TableRelajacion = new org.jdesktop.swingx.JXTable();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setToolTipText("Metodos Iterativos Abiertos");

        TableA.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(TableA);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/help.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        TableB.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jScrollPane2.setViewportView(TableB);

        TableX.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(TableX);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Metodos Iterativos Abiertos"));
        jPanel3.setToolTipText("Panel Metodos Iterativos Abiertos");

        jLabel8.setText("Tolerancia");

        FieldIteraciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FieldIteracionesActionPerformed(evt);
            }
        });

        FieldRelajacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FieldRelajacionActionPerformed(evt);
            }
        });

        FieldTolerancia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FieldToleranciaActionPerformed(evt);
            }
        });

        jLabel7.setText("Iteraciones");

        jLabel9.setText("Relajacion");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(FieldIteraciones, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(FieldTolerancia, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FieldRelajacion))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(FieldIteraciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FieldTolerancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FieldRelajacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        BotonJacobi.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/kblackbox.png"))); // NOI18N
        BotonJacobi.setText("Metodo de Jacobi");
        BotonJacobi.setToolTipText("Metodo de Jacobi");
        BotonJacobi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonJacobiActionPerformed(evt);
            }
        });

        BotonGaussSeidelRelax.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/kcmpartitions.png"))); // NOI18N
        BotonGaussSeidelRelax.setText("Metodo de Gauss-Seidel");
        BotonGaussSeidelRelax.setToolTipText("Metodo de Gauss - Seidel con Relajacion");
        BotonGaussSeidelRelax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGaussSeidelRelaxActionPerformed(evt);
            }
        });

        jScrollPane5.setBorder(javax.swing.BorderFactory.createTitledBorder("Valores Iniciales"));

        TableRelajacion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TableRelajacion.setToolTipText("Valores iniciales para cada variable. por defecto 0");
        jScrollPane5.setViewportView(TableRelajacion);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 175, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(BotonGaussSeidelRelax, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BotonJacobi, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE))
                .addGap(26, 26, 26))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(BotonJacobi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BotonGaussSeidelRelax)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jLabel4.setText("Matriz A");

        jLabel5.setText("Vector B");

        jLabel6.setText("Vector X");

        jLabel1.setText("Metodos Iterativos Abiertos");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(16, 16, 16))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addGap(1, 1, 1)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        NuMethodApp.helpLauncher("Jacobiygauss-seidel");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void FieldIteracionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FieldIteracionesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FieldIteracionesActionPerformed

    private void FieldToleranciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FieldToleranciaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FieldToleranciaActionPerformed

    private void FieldRelajacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FieldRelajacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FieldRelajacionActionPerformed

    /**
     * Metodo que extrae de los textfield`s los valores de los parametros
     * para los metodos iterativos.
     */
    private void getParamsForIteratives (int iter1, double tol1, double[] initial, double relajacion1) throws NumberFormatException{
            iter1 = Integer.parseInt(FieldIteraciones.getText());
            tol1 = Double.parseDouble(FieldTolerancia.getText());
            relajacion1 = Double.parseDouble(FieldRelajacion.getText());
            
            for (int i = 0 ; i < TableRelajacion.getModel().getColumnCount(); i++){
                if (TableRelajacion.getModel().getValueAt(0, i) != null){
                    //Obtener desde la interfaz.
                    initial[i] = Double.parseDouble((String)TableRelajacion.getModel().getValueAt(0, i));
                }
                else{
                    //Iniciar en 0 por defecto
                    initial[i] = 0;
                }
            }
    }
    private void BotonJacobiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonJacobiActionPerformed
        try {
            int rowCount = this.TableA.getModel().getRowCount();
            int columnCount = this.TableA.getModel().getColumnCount();
            double[][] A = new double[rowCount][columnCount];
            double[] B = new double[rowCount];
            double[] X = new double[columnCount];
            double relajacion = new Double(0);


            double[] initial = new double[TableRelajacion.getModel().getColumnCount()];
            int iter = 0;
            double tol = 0;

            //Llenar las variable A y B desde las tablas
            getDataFromTables(A, B);

            //Obtener los datos para la Jacobi
            //getParamsForIteratives(iter, tol, initial, relajacion);
            iter = Integer.parseInt(FieldIteraciones.getText());
            tol = Double.parseDouble(FieldTolerancia.getText());
            relajacion = Double.parseDouble(FieldRelajacion.getText());

            for (int i = 0 ; i < TableRelajacion.getModel().getColumnCount(); i++){
                if (TableRelajacion.getModel().getValueAt(0, i) != null){
                    //Obtener desde la interfaz.
                    initial[i] = Double.parseDouble((String)TableRelajacion.getModel().getValueAt(0, i));
                }
                else{
                    //Iniciar en 0 por defecto
                    initial[i] = 0;
                }
            }
            //Las variables estan llenas si se garantiza que habian numeros en las tablas
            //Usarlas
            X = Jacobi.solucionar(A, B, initial, tol, iter);
            //Metodo para colocar datos en la tablaX
            setDataToTableX(X);
        } catch (NullPointerException npe) {
            JOptionPane.showMessageDialog(this, "Sucedio el siguiente Error ejecutando a Jacobi: " +
                    "\n" + npe.getLocalizedMessage());
        } catch (NumberFormatException nfe){
            JOptionPane.showMessageDialog(this, "Oops");
        }
    }//GEN-LAST:event_BotonJacobiActionPerformed

    private void BotonGaussSeidelRelaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGaussSeidelRelaxActionPerformed
        try {
            int rowCount = this.TableA.getModel().getRowCount();
            int columnCount = this.TableA.getModel().getColumnCount();
            double[][] A = new double[rowCount][columnCount];
            double[] B = new double[rowCount];
            double[] X = new double[columnCount];
            double relajacion = new Double(0);


            double[] initial = new double[TableRelajacion.getModel().getColumnCount()];
            int iter = 0;
            double tol = 0;

            //Llenar las variable A y B desde las tablas
            getDataFromTables(A, B);

            //Obtener los datos para la Jacobi
            //getParamsForIteratives(iter, tol, initial, relajacion);
            iter = Integer.parseInt(FieldIteraciones.getText());
            tol = Double.parseDouble(FieldTolerancia.getText());
            relajacion = Double.parseDouble(FieldRelajacion.getText());

            for (int i = 0 ; i < TableRelajacion.getModel().getColumnCount(); i++){
                if (TableRelajacion.getModel().getValueAt(0, i) != null){
                    //Obtener desde la interfaz.
                    initial[i] = Double.parseDouble((String)TableRelajacion.getModel().getValueAt(0, i));
                }
                else{
                    //Iniciar en 0 por defecto
                    initial[i] = 0;
                }
            }
            //Las variables estan llenas si se garantiza que habian numeros en las tablas
            //Usarlas
            X = GaussSeidel.solucionar(A, B, initial, tol, iter);
            //Metodo para colocar datos en la tablaX
            setDataToTableX(X);
        } catch (NullPointerException npe) {
            JOptionPane.showMessageDialog(this, "Sucedio el siguiente Error ejecutando a Jacobi: " +
                    "\n" + npe.getLocalizedMessage());
        } catch (NumberFormatException nfe){
            JOptionPane.showMessageDialog(this, "Oops");
        }
    }//GEN-LAST:event_BotonGaussSeidelRelaxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonGaussSeidelRelax;
    private javax.swing.JButton BotonJacobi;
    private javax.swing.JTextField FieldIteraciones;
    private javax.swing.JTextField FieldRelajacion;
    private javax.swing.JTextField FieldTolerancia;
    private org.jdesktop.swingx.JXTable TableA;
    private org.jdesktop.swingx.JXTable TableB;
    private org.jdesktop.swingx.JXTable TableRelajacion;
    private org.jdesktop.swingx.JXTable TableX;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    // End of variables declaration//GEN-END:variables

    public static void main(String[] args) {
        JFrame myFrame = new JFrame("Test");
        PanelIterativosAbiertos m = new PanelIterativosAbiertos();
        //myFrame.setLayout(new FlowLayout());
        myFrame.add(m);

        myFrame.pack();
        myFrame.setVisible(true);


    }
}
